<?php
/**
 * Created by JetBrains PhpStorm.
 * User: zhouyang
 * Date: 13-7-15
 * Time: 下午4:31
 * To change this template use File | Settings | File Templates.
 */
class TagsModel extends Model{
    //根据tag_id 获取 tag 信息
    public function get($tag_id){
        return $this->dbreader()->get($tag_id);
    }

    //根据tag_name 获取 tag 信息
    public function getTagInfoByName($tag_name){
        return $this->dbreader()->getTagInfoByName($tag_name);
    }

    //获取标签信息列表<带分页>
    public function getTagList($curr_page,$per_page,$filter = array()){
        return $this->dbreader()->getTagList($curr_page,$per_page,$filter);
    }

    //获取所有标签信息
    public function getTags($filter = array()){
        return $this->dbreader()->getTags($filter);
    }

    //添加标签信息
    public function addTag($tag_name){
        if(!trim_space($tag_name)){
            return false;
        }
        $tag_info = $this->getTagInfoByName($tag_name);
        if($tag_info){
            return $tag_info['tag_id'];
        }

        return $this->dbreader()->addTag($tag_name);
    }

    //删除标签信息
    public function delTag($tag_id){
        return $this->dbreader()->delTag($tag_id);
    }

    //更新标签信息
    public function updateTag($id,$name){
        return $this->dbreader()->updateTag($id,$name);
    }
}